package com.nowar.common.proxy;

import com.nowar.common.proxy.inter.TestInterface;
import com.nowar.common.proxy.inter.impl.TestInterfaceImpl;
import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.InitializingBean;

import java.lang.reflect.Proxy;

/**
 * 初始化接口类
 *
 * @Author: 谢无殇。
 * @Date : 2023-10-29 22:31
 */
public class CommonFactoryBean implements FactoryBean, InitializingBean {


    private TestInterface testInterface;

    @Override
    public Object getObject() throws Exception {
        if (testInterface == null) {
            afterPropertiesSet();
        }
        return testInterface;
    }

    @Override
    public Class<?> getObjectType() {
        return testInterface.getClass();
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        /**
         * 初始化接口类，或从是spring容器获取，成员属性怎么获取
         */
        TestInterfaceImpl testInterface1 = new TestInterfaceImpl();
        testInterface1.setId("1");
        testInterface1.setName("1");
        testInterface1.setPassword("1");
        testInterface1.setIp("1");
        testInterface1.setHost("1");
        this.testInterface = testInterface1;
    }
}
